package com.dolphin.common.component.var.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

@Getter
public enum MySqlFieldTypeEnum {
    INT("int", FiledTypeEnum.INTEGER),
    TINYINT("tinyint", FiledTypeEnum.INTEGER),
    SMALLINT("smallint", FiledTypeEnum.INTEGER),
    MEDIUMINT("mediumint", FiledTypeEnum.INTEGER),
    BIGINT("bigint", FiledTypeEnum.LONG),
    FLOAT("float", FiledTypeEnum.FLOAT),
    DOUBLE("double", FiledTypeEnum.DOUBLE),
    DECIMAL("decimal", FiledTypeEnum.BIG_DECIMAL),
    DATE("date", FiledTypeEnum.DATE),
    DATETIME("datetime", FiledTypeEnum.DATE),
    TIMESTAMP("timestamp", FiledTypeEnum.DATE),
    CHAR("char", FiledTypeEnum.STRING),
    VARCHAR("varchar", FiledTypeEnum.STRING),
    TINYBLOB("tinyblob", FiledTypeEnum.STRING),
    TINYTEXT("tinytext", FiledTypeEnum.STRING),
    BLOB("blob", FiledTypeEnum.STRING),
    TEXT("text", FiledTypeEnum.STRING)
    ;

    private String fieldType;
    private FiledTypeEnum valueType;

    MySqlFieldTypeEnum(String fieldType, FiledTypeEnum valueType) {
        this.fieldType = fieldType;
        this.valueType = valueType;
    }

    public static String getByFieldType(String fieldType){
        if(StringUtils.isEmpty(fieldType)){
            return null;
        }

        for(MySqlFieldTypeEnum item : values()){
            if(Objects.equals(fieldType, item.fieldType)){
                return item.getValueType().name().toUpperCase();
            }
        }

        return null;
    }
}
